package com.machinsight.library.model;

import com.machinsight.library.bean.LoginUser;
import com.machinsight.library.dao.SqlSessionController;
import com.machinsight.library.dao.bean.UserInfoEntity;
import org.apache.ibatis.session.SqlSession;

import java.io.IOException;

/**
 * Copyright ©2017-2020 Machinsight Technology Co., Ltd.All rights reserved.
 * Author: Zhoushaohua
 * Date: 2020/1/2
 * Description:登录业务Model实现类
 */
public class LoginBusinessModelImpl implements ILoginBusinessModel {

    @Override
    public UserInfoEntity queryUserByLoginUser(LoginUser loginUser) {
        UserInfoEntity userInfoEntity = null;
        SqlSession sqlSession = null;
        try {
            sqlSession = SqlSessionController.getInstance().openSession();
            if (sqlSession != null) {
                userInfoEntity = sqlSession.selectOne(
                        "com.machinsight.library.dao.mapper.IUserMapper.findUserByNameAndPwd",
                        loginUser);
            }
        } catch (IOException e) {
            System.out.println(e.toString());
        } finally {
            SqlSessionController.getInstance().closeSession(sqlSession);
        }
        return userInfoEntity;
    }
}
